package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.product.domain.ProductCategory;
import com.ruoyi.product.domain.Shopping.SUM;
import com.ruoyi.product.domain.SpecProduct;
import com.ruoyi.product.domain.vo.SpecProductVo;
import com.ruoyi.product.service.IManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.product.domain.Shopping.Management;
import com.ruoyi.product.service.IManagementService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品管理表Controller
 * 
 * @author cs
 * @date 2024-07-26
 */
@RestController
@RequestMapping("/management")
public class ManagementController extends BaseController
{
    @Autowired
    private IManagementService managementService;

    /**
     * 查询商品管理表列表
     */
    @RequiresPermissions("management:management:list")
    @GetMapping("/list")
    public TableDataInfo list(Management management)
    {
        startPage();
        List<Management> list=managementService.selectManagementList(management);
        return getDataTable(list);
    }

    /**
     * 导出商品管理表列表
     */
    @RequiresPermissions("management:management:export")
    @Log(title = "商品管理表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Management management)
    {
        List<Management> list = managementService.selectManagementList(management);
        ExcelUtil<Management> util = new ExcelUtil<Management>(Management.class);
        util.exportExcel(response, list, "商品管理表数据");
    }

    @RequiresPermissions("management:management:chage")
    @GetMapping("chenge")
    public AjaxResult change(Management management){
        return success(managementService.change(management));
    }

    /**
     * 获取商品管理表详细信息
     */
    @RequiresPermissions("management:management:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(managementService.selectManagementById(id));
    }
    @RequiresPermissions("management:management:treeselect")
    @GetMapping("/treeselect")
    public List<ProductCategory> treeselect(){
        return managementService.treeselect();
    }
    @RequiresPermissions("/management/management/sepcList")
    @GetMapping("/sepcList")
    public List<SpecProductVo> specList(){
        return managementService.specList();
    }
    /**
     * 新增商品管理表
     */
    @RequiresPermissions("management:management:add")
    @Log(title = "商品管理表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SUM sum)
    {
        return toAjax(managementService.insertManagement(sum));
    }

    /**
     * 修改商品管理表
     */
    @RequiresPermissions("management:management:edit")
    @Log(title = "商品管理表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SUM sum)
    {
        return toAjax(managementService.updateManagement(sum));
    }

    /**
     * 删除商品管理表
     */
    @RequiresPermissions("management:management:remove")
    @Log(title = "商品管理表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(managementService.deleteManagementByIds(ids));
    }
}
